//------------------------------------------------------------------------------
// PasCassa - a Delphi/Pascal class library for Apache Cassandra
//
// Copyright (c) 2010-2013 Jens Geyer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//------------------------------------------------------------------------------
unit Database.ReadWrite.Client;

interface

uses
  Classes, Windows, SysUtils, DateUtils, Math,
  Generics.Collections,
  Cassandra_200,
  Cassandra.Client,
  Thrift,
  Thrift.Transport,
  Thrift.Protocol,
  Thrift.Collections,
  Thrift.Server,
  Thrift.Stream,
  Thrift.Console,
  Thrift.Utils,
  DataModel.Entity.TestData,
  ReadWrite.Constants;


type
  ITestDataDatabaseClient = interface( PasCassa.IClient)
    ['{257BA891-328A-4C81-B300-92FFAAE8D53B}']

    // data access
    function  TestData : PasCassa.IColumnFamily;
  end;


  TTestDataDatabaseClient = class( PasCassa.TClient, ITestDataDatabaseClient)
  strict private
    FTestData : PasCassa.IColumnFamily;

  strict protected
    function DefineKeyspace( const aKeyspace : string) : IKsDef;  override;

    // ITestDataDatabaseClient
    function  TestData : PasCassa.IColumnFamily;

  public
    constructor Create( aServer : string = TESTDATA_DBSERVER_NAME;
                        aPort : Integer  = TESTDATA_DBSERVER_PORT);
  end;


implementation


//--- TTestDataDatabaseClient -----------------------------------------------------------------------


constructor TTestDataDatabaseClient.Create( aServer : string; aPort : Integer);
begin
  inherited Create( aServer, aPort);

  FTestData := TTestDataFamily.Create( ExtendedAPI, CF_TESTDATA);

  ColumnFamilies.Add( FTestData);
end;


function TTestDataDatabaseClient.DefineKeyspace( const aKeyspace : string) : IKsDef;
// may be overriden, as necessary
begin
  result := inherited DefineKeyspace( aKeyspace);

  // replicas
  result.Replication_factor := REPLICAS;  // deprecated
  result.Strategy_options.Add('replication_factor', IntToStr(REPLICAS));
end;


function TTestDataDatabaseClient.TestData : PasCassa.IColumnFamily;
begin
  result := FTestData;
end;


end.

